home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / mail / thor201.lha / THOR_2.0 / thor.lha / rexx / ForwardMsg.thor < prev    next >
Text File  |  1995-05-15  |  6KB  |  269 lines

  1. /* $VER: ForwardMsg.thor 3.1 (17.11.94)
  2. **
  3. ** Arexx script to forward messages from a user to another user.
  4. **
  5. ** Must be started from THOR.
  6. **
  7. ** Script by: Petter Nilsen, Ultima Thule Software.
  8. **/
  9.  
  10. options results
  11.  
  12.  
  13. EVE_ENTERMSG     =  0   /* Enter message */
  14.  
  15. thorport = address()
  16.  
  17. if ~show('p', 'BBSREAD') then do
  18.     address command
  19.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  20.         "WaitForPort BBSREAD"
  21. end
  22.  
  23. address(thorport)
  24.  
  25. CURRENTMSG stem MSG
  26. if(rc ~= 0) then
  27. do
  28.     REQUESTNOTIFY TEXT '"No current message."' BT '"_Ok"'
  29.     exit
  30. end
  31.  
  32. REQUESTNOTIFY TEXT '"Forward to the same system and conference ?"' BT '" _Yes | _No "'
  33. if(rc ~= 0) then
  34. do
  35.     say THOR.LASTERROR
  36.     exit
  37. end
  38.  
  39. if(result = 0) then 
  40. do
  41.     address BBSREAD GETBBSLIST stem BBSLIST
  42.     if(rc ~= 0) then goto quit
  43.  
  44.     REQUESTLIST instem BBSLIST title '"Select system to forward to:"'
  45.     if(rc ~= 0) then 
  46.     do
  47.         if(rc ~= 5) then address(thorport) REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  48.         exit
  49.     end
  50.  
  51.     bbs = result
  52.  
  53.     address BBSREAD GETCONFLIST bbsname '"'bbs'"' stem CONFLIST
  54.     if(rc ~= 0) then goto quit
  55.  
  56.     REQUESTLIST instem CONFLIST title '"Select Conference:"'
  57.     if(rc ~= 0) then 
  58.     do
  59.         if(rc ~= 5) then address(thorport) REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  60.         exit
  61.     end
  62.     conf = result
  63.     other = 1
  64. end
  65. else
  66. do
  67.     other = 0
  68.     bbs = MSG.BBSNAME
  69.     conf = MSG.CONFNAME
  70. end
  71.  
  72. /* Let's ask for a user name.. */
  73.  
  74. do forever
  75.     REQUESTSTRING TITLE '"Enter username to forward to:"' BT '" _Ok | _Cancel "' MAXCHARS 200
  76.     if(rc ~= 0) then exit
  77.     forwardto = result
  78.  
  79.  
  80.     if(upper(forwardto) ~= "ALL") then
  81.     do
  82.         address(bbsread)
  83.  
  84.         /*
  85.             The message was not addressed to 'ALL', 
  86.             let's search for the user on the system
  87.             the message is to be forwarded to. 
  88.             Both name, addresses and aliases will be searched 
  89.             for to find a match.
  90.         */
  91.  
  92.         SEARCHBRUSER bbsname '"'bbs'"' stem USERS search '"'forwardto'"' name address alias suggestusersstem SUG
  93.         if(rc ~= 0) then goto quit
  94.  
  95.         if(result > 0) then
  96.         do
  97.             /* Ok, we found one or more users matching the data entered exactly */
  98.  
  99.             address(bbsread)
  100.  
  101.             drop LIST.
  102.             drop USERTAGS.
  103.  
  104.             LIST.COUNT = USERS.COUNT
  105.  
  106.             /*
  107.                 We must build a list of user names suitable to 
  108.                 be viewed with the REQUESTLIST command.
  109.             */
  110.  
  111.             do n = 1 to USERS.COUNT
  112.                 LIST.n.USERNR = USERS.n.USERNR
  113.                 READBRUSER bbsname '"'bbs'"' usernr USERS.n.USERNR tagsstem USERTAGS
  114.                 if(rc ~= 0) then goto quit
  115.                 LIST.n = USERTAGS.NAME
  116.  
  117.                 if(symbol("USERTAGS.ADDRESS") = "VAR") then 
  118.                     LIST.n.ADDRESS = USERTAGS.ADDRESS
  119.             end
  120.  
  121.             /* Select a user */
  122.  
  123.             address(thorport)
  124.             REQUESTLIST instem LIST title '"Select user:"'
  125.             if(rc ~= 0) then 
  126.             do
  127.                 if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  128.                 exit
  129.             end
  130.  
  131.             forwardto = result
  132.  
  133.             /* We might have an address (email address/Fido address etc.) */
  134.  
  135.             do n = 1 to LIST.COUNT
  136.                 if(LIST.n = forwardto) then
  137.                     forwardaddress = LIST.n.ADDRESS
  138.             end
  139.             leave
  140.         end
  141.         else
  142.         do
  143.             /*
  144.                 No users matching the given data exactly were found,
  145.                 let's prosess the suggestions.
  146.             */
  147.  
  148.             if(symbol("SUG.COUNT") = "VAR") then do
  149.                 address(thorport)
  150.                 REQUESTLIST instem SUG title '"Select user:"'
  151.                 if(rc ~= 0) then 
  152.                 do
  153.                     if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  154.                     exit
  155.                 end
  156.  
  157.                 forwardto = result
  158.  
  159.                 /* Let's find the user number of the user selected */
  160.  
  161.                 do n = 1 to SUG.COUNT
  162.                     if(SUG.n = forwardto) then
  163.                         usernumber = SUG.n.USERNR
  164.                 end
  165.  
  166.                 drop USERTAGS.
  167.  
  168.                 address(bbsread)
  169.  
  170.                 /* Get some data about the user selected */
  171.  
  172.                 READBRUSER bbsname '"'bbs'"' usernr usernumber tagsstem USERTAGS
  173.                 if(rc ~= 0) then goto quit
  174.  
  175.                 if(symbol("USERTAGS.ADDRESS") = "VAR") then 
  176.                     forwardaddress = USERTAGS.ADDRESS
  177.  
  178.                 leave
  179.             end
  180.             else
  181.             do
  182.                 /* No users were found in the search */
  183.  
  184.                 address(thorport)
  185.                 REQUESTNOTIFY TEXT '"No matching users found, try again?"' BT '"_Ok | _Cancel"'
  186.                 if(rc ~= 0) then exit
  187.                 if(result = 0) then exit
  188.             end
  189.         end
  190.     end
  191.     else
  192.         leave
  193. end
  194.  
  195. address(bbsread)
  196.  
  197. /* Get a unique message for the event */
  198.  
  199. UNIQUEMSGFILE bbsname '"'bbs'"' stem UNIQUEFILE
  200. if(rc ~= 0) then goto quit
  201.  
  202. /* Read the data on the message that is to be forwarded */
  203.  
  204. READBRMESSAGE bbsname '"'MSG.BBSNAME'"' confname '"'MSG.CONFNAME'"' msgnr MSG.MSGNR headstem HEADTAGS textstem TEXTTAGS 
  205. if(rc ~= 0) then goto quit
  206.  
  207. if(~open(fh, UNIQUEFILE.NAME, 'A')) then 
  208. do
  209.     address(thorport)
  210.     REQUESTNOTIFY TEXT '"Unable to open file:' UNIQUEFILE.NAME '"' BT '"_Ok"'
  211.     exit
  212. end
  213.  
  214. /* Build the forwarded message */
  215.  
  216. msgfrom = HEADTAGS.FROMNAME
  217. msgto = ''
  218. if(symbol("HEADTAGS.TONAME") = "VAR") then msgto = HEADTAGS.TONAME
  219. if(symbol("HEADTAGS.TOADDR") = "VAR") then msgto = msgto || ' <' || HEADTAGS.TOADDR || '>'
  220. if(symbol("HEADTAGS.FROMADDR") = "VAR") then msgfrom = msgfrom || ' <' || HEADTAGS.FROMADDR || '>'
  221. call writeln(fh, '--------- START OF FORWARDED MESSAGE ---------')
  222. call writeln(fh, '')
  223.  
  224. if(other = 1) then 
  225. do
  226.     call writeln(fh, 'From System ....: ' || MSG.BBSNAME)
  227.     call writeln(fh, 'From Conference : ' || MSG.CONFNAME)
  228. end
  229.  
  230. if(symbol("HEADTAGS.ORGINALNR") = "VAR") then do 
  231.     call writeln(fh, 'MessageNr ......: ' || HEADTAGS.ORGINALNR)
  232. end
  233. if(symbol("HEADTAGS.MSGID") = "VAR") then do 
  234.     call writeln(fh, 'MessageID ......: '|| HEADTAGS.MSGID)
  235. end
  236.  
  237. call writeln(fh, 'Originally from : ' || msgfrom)
  238. if(msgto ~= '') then do
  239.     call writeln(fh, 'Originally to ..: ' || msgto)
  240. end
  241. call writeln(fh, 'Subject ........: ' || HEADTAGS.SUBJECT || '0a'x)
  242.  
  243. do n=1 to TEXTTAGS.TEXT.COUNT
  244.     call writeln(fh, TEXTTAGS.TEXT.n)
  245. end
  246. call writeln(fh, '')
  247. call writeln(fh, '---------- END OF FORWARDED MESSAGE ----------')
  248.  
  249. call close(fh)
  250.  
  251. /* Post it */
  252.  
  253. drop EVENT.
  254.  
  255. EVENT.SUBJECT = 'FWD: '||HEADTAGS.SUBJECT
  256. EVENT.TONAME = forwardto
  257. EVENT.TOADDR = forwardaddress
  258. EVENT.CONFERENCE = conf
  259. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  260.  
  261. WRITEBREVENT bbsname '"'bbs'"' event EVE_ENTERMSG stem EVENT
  262. if(rc ~= 0) then goto quit
  263. exit
  264.  
  265. quit:
  266.     address(thorport)
  267.     REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  268.     exit
  269.